<?php
    // --------------------------------------
    // Paths
    // --------------------------------------
    define('SITE_BASE',     dirname(dirname(__FILE__)));
    define('CONFIG',        SITE_BASE.'/config');
    define('VENDOR',        SITE_BASE.'/vendor');
    define('MODELS',        SITE_BASE.'/app/models');
    define('CONTROLLERS',   SITE_BASE.'/app/controllers');
    define('VIEWS',         SITE_BASE.'/app/views');
    define('HELPERS',       SITE_BASE.'/app/helpers');
    define('LIB',           SITE_BASE.'/lib');
    define('LOG',           SITE_BASE.'/log');
    define('CACHE',         SITE_BASE.'/cache');
    define('PLUGINS',       SITE_BASE.'/plugins');
    define('TESTS',         SITE_BASE.'/test/unit');
    define('PUBLIC_HTML',   SITE_BASE.'/../public_html');

    // --------------------------------------
    // charset
    // --------------------------------------
    define("DEFAULT_CHARSET", "UTF-8");

    // --------------------------------------
    // include path 
    // --------------------------------------
    // uncomment if you put your own custom scripts 
    // in the top level pixel/lib folder
    // ini_set('include_path', LIB.PATH_SEPARATOR.ini_get('include_path'));
    
    // --------------------------------------
    // Password Salt - for passwords
    // --------------------------------------
    // change this for your app
    define('PIXEL_SALT', 'p!x3l4pP');
    
    // --------------------------------------
    // runtime settings 
    // --------------------------------------
    ini_set('session.use_trans_sid',    0);
    ini_set('magic_quotes_gpc',         0);
    ini_set('magic_quotes_runtime',     0);
    
    // --------------------------------------
    // setup global var for putting stuff in.
    // --------------------------------------
    $GLOBALS['PIXEL'] = array();    
    
    // --------------------------------------
    // mode
    // --------------------------------------
    if ( !defined('PIXEL_MODE') )
    {
        define('PIXEL_MODE', 'development');        
    }
    require CONFIG.'/environments/'.PIXEL_MODE.'.php';
    
    // --------------------------------------
    // errors
    // --------------------------------------
    require CONFIG.'/errors.php';
    define('PIXEL_PAGE_NOT_FOUND','404.html');
    
    // --------------------------------------
    // load database settings
    // --------------------------------------
    define('DB_DATESTAMP', date("Y-m-d H:i:s"));
    $GLOBALS['PIXEL']['DB'] = parse_ini_file(CONFIG.'/database.php',true);
    define('DB_PREFIX', $GLOBALS['PIXEL']['DB'][PIXEL_MODE]['db_prefix']);
    
    // --------------------------------------
    // some form defaults
    // --------------------------------------
    $GLOBALS['PIXEL']['DEFAULT_SUBMIT_OPTIONS'] = array('class'=>'submit');
    $GLOBALS['PIXEL']['DEFAULT_BUTTON_OPTIONS'] = array('class'=>'submit');
    
    // --------------------------------------
    // main includes
    // --------------------------------------  
    require VENDOR.'/pixel/ActionController.php';    
    require VENDOR.'/pixel/ActiveRecord.php';
    include VENDOR.'/pixel/lib/lib.helper_functions.php';  
    
    // Unset any variables instantiated as a result of 
    // register_globals being enabled			
	if (@ini_get('register_globals')) unregister_globals();  
	
	// stripslashes if magic_quotes is on
	if(get_magic_quotes_gpc()) strip_get_post_slashes();
    
    // --------------------------------------
    // ADODB session storage
    // note - only uncomment after install, bascially
    // once the sessions table exists.
    // --------------------------------------
    /*
    $ADODB_SESSION_DRIVER  = $GLOBALS['PIXEL']['DB'][PIXEL_MODE]['driver'];
    $ADODB_SESSION_CONNECT = $GLOBALS['PIXEL']['DB'][PIXEL_MODE]['host'];
    $ADODB_SESSION_USER    = $GLOBALS['PIXEL']['DB'][PIXEL_MODE]['username'];
    $ADODB_SESSION_PWD     = $GLOBALS['PIXEL']['DB'][PIXEL_MODE]['password'];
    $ADODB_SESSION_DB      = $GLOBALS['PIXEL']['DB'][PIXEL_MODE]['database'];

    include VENDOR.'/adodb/session/adodb-session.php';
    adodb_sess_open(false,false,false);
    #ADODB_Session::debug(true);
    */
    // if you want to save your sessions locally, instead of /tmp or in db
    // uncomment and make this folder writable by server.
    //session_save_path(CACHE.'/sessions');
    session_start();
    
    // --------------------------------------
    // Routes
    // --------------------------------------    
    $GLOBALS['PIXEL']['routes'] = array();
    // routes in the system, just use regex pattern matching
    // add_route("#/blog/(?P<year>\d{4})/?$#", array('controller'=>'blog','action'=>'read')); 
    // the variable 'year' will also become available in the $this->params array. 
    // you can overwrite any matches with the passed array to 
    // add_route(string pattern, array options);
    
    // to hook up your default controller, just do this:
    // add_route("#^$#",array('controller'=>'yourcontroller','action'=>'theaction'))
        
    // admin router
    add_route("#^admin/?$#",
              array(
                    'controller'=>'admin/dashboard',
                    'action'=>'index'
                    )
             );
    
    // admin controllers
    add_route("#^admin/(?P<controller>[a-zA-Z_]+)/?(?P<action>[a-zA-Z_]+)?$#");  
        
    // content controller gets to serve up the homepage
    add_route("#^$#",
               array(
                     'controller'=>'content',
                     'action'=>'index'
                     )
              );
    
    // render page/name-of-page    
    add_route("#^content/?(?P<page>[-a-zA-Z_0-9]+)?$#",
              array(
                     'controller'=>'content',
                     'action'=>'index'
                   )
              );
    
    // news article
    add_route("#^news/read/(?P<id>.+)$#",
              array(
                    'controller'=>'news',
                    'action'=>'read'
                    )
             );
     // news article
     add_route("#^news/preview/(?P<id>.+)$#",
               array(
                     'controller'=>'news',
                     'action'=>'preview'
                     )
              );
    
    // news articles by category
    add_route("#^news/category/(?P<id>.+)$#",
              array(
                    'controller'=>'news',
                    'action'=>'category'
                    )
             );
    
    // news articles by archives                    
    add_route("#^news/archives/(?P<year>\d{4})/?(?P<month>\d{1,2})?$#",
               array(
                     'controller'=>'news',
                     'action'=>'archives'
                     )
             );
    
    // default match
    add_route("#^(?P<controller>[a-zA-Z0-9_]+)/?(?P<action>[a-zA-Z0-9_]+)?$#");
?>